package com.auto.learning.activity;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler.Callback;
import android.os.Message;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.auto.learning.R;
import com.auto.learning.adapter.CommentAdapter;
import com.auto.learning.bean.CommentBean;
import com.auto.learning.bean.ResponeResult;
import com.auto.learning.event.EventBus;
import com.auto.learning.event.Handle;
import com.auto.learning.event.LoginSuccessEvent;
import com.auto.learning.event.listener.DialogListener;
import com.auto.learning.net.HttpCommonInfo;
import com.auto.learning.net.HttpHelper;
import com.auto.learning.net.HttpRequestHelper;
import com.auto.learning.service.MyUserInfo;
import com.auto.learning.sharesdk.tools.ShareOpUtils;
import com.auto.learning.thread.pool.Pool;
import com.auto.learning.tools.CommonMethod;
import com.auto.learning.tools.FastBlur;
import com.auto.learning.tools.TemporaryVariable;
import com.auto.learning.view.CommonAlertDialog;
import com.auto.learning.view.MyPopWindowDialog;
import com.auto.learning.view.ShareView;
import com.auto.learning.view.MyPopWindowDialog.IPopDialogOnclickInterface;
import com.auto.learning.view.PullToRefreshListView;
import com.auto.learning.view.PullToRefreshListView.OnRefreshListener;
import com.auto.learning.view.SharedPreferencesUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.nostra13.universalimageloader.core.ImageLoader;

public class CommentActivity extends Activity implements Callback{
	private final static int CLICK_FAVOR = 2;
	private final static int CLICK_FAVOR_SUCCESS = 3;
	private final static int CLICK_FAVOR_FAILE = 4;
	private final static int ADD_FAVOR_SUCCESS = 5;
	private final static int DELETE_COMMENT_SUCCESS = 6;
	private final static int DELETE_COMMENT_FAIL = 7;
	
	private ImageView image_render;
	private View view,text2;
	private int bookId;
	private String bookName,imgFacePlay;
	
	private PullToRefreshListView comment_listview;
	private CommentAdapter adapter;
	private ArrayList<CommentBean> list = new ArrayList<CommentBean>();
	
	private int pageIndex = 0;
	
	private View lvProductFooter;
	private TextView lvProductFooterMore,tv_comment;
	private ProgressBar lvProductFooterProgress;
	private TextView lvBtn_more;
	private LinearLayout lvLinear_more,activity_base_title;
	private RelativeLayout rel_mid,rel_main;
	private EditText et_comment;
	private ScrollView main_view;
	private View view_edit;
	
	private Handle handle = new Handle(this){
		public void handleMessage(android.os.Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case HttpRequestHelper.GETDATA_SUCCESS:
				String bottom = "";
				ResponeResult result =(ResponeResult) msg.obj;
				ArrayList<CommentBean> resultList = new Gson().fromJson(result.getData(), new TypeToken<ArrayList<CommentBean>>() {}.getType());
				if (pageIndex == 0) {
					list.clear();
					list.addAll(resultList);
				} else {
					list.addAll(resultList);
				}
				if (resultList.size() >= 20) {
					pageIndex ++;
					lvBtn_more.setVisibility(View.VISIBLE);
					lvProductFooterMore.setText(bottom);
				}else {
					bottom = "没有更多数据了";
					lvLinear_more.setVisibility(View.VISIBLE);
					lvProductFooterMore.setText(bottom);
					lvProductFooterProgress.setVisibility(View.GONE);
					lvBtn_more.setVisibility(View.GONE);
				}
				
				if (comment_listview != null) {
					comment_listview.onRefreshComplete();
					comment_listview.setTag(0);
				}
				if (list != null && list.size() > 0) {
					adapter.notifyDataSetChanged();
				}
				break;
			case CLICK_FAVOR:
				addFavor((int)msg.obj);
				break;
			case CLICK_FAVOR_SUCCESS:
				ResponeResult favor_result = (ResponeResult)msg.obj;
				int commendId = favor_result.getCode();
				for (int i = 0; i < list.size(); i++) {
					if (list.get(i).getId() == commendId) {
						list.get(i).setFavourNum(list.get(i).getFavourNum() + 1);
						break;
					}
				}
				if (adapter != null) {
					adapter.notifyDataSetChanged();
				}
//				CommonMethod.makeNotice(CommentActivity.this, "点赞成功");
				break;
			case CLICK_FAVOR_FAILE:
				tv_comment.setTag("0");
				ResponeResult favor_result_fail = (ResponeResult)msg.obj;
				CommonMethod.makeNotice(CommentActivity.this, favor_result_fail.getMsg());
				break;
			case ADD_FAVOR_SUCCESS:
				tv_comment.setTag("0");
				et_comment.setText("");
				et_comment.setHint("发表读后感...");
				InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
				imm.hideSoftInputFromWindow(et_comment.getWindowToken(), 0);
				ResponeResult add_result = (ResponeResult)msg.obj;
				CommentBean addBean =  new Gson().fromJson(add_result.getData(), new TypeToken<CommentBean>() {}.getType());
				if (list != null) {
					list.add(0,addBean);
					adapter.notifyDataSetChanged();
					comment_listview.setSelection(0);
				}
				break;
			case HttpRequestHelper.PUBLIC_LOGIN_SUCCESS:
				CommonMethod.makeNotice(CommentActivity.this, "登录成功");
				ResponeResult login_result = (ResponeResult) msg.obj;
				if(login_result != null){
					EventBus.getEventBus("login_success_refreshUI").post(login_result);
				}
				view_edit.setVisibility(View.GONE);
				break;
			case HttpRequestHelper.PUBLIC_LOGIN_FAIL:
				CommonMethod.makeNotice(CommentActivity.this, msg.obj.toString());
				break;
			case DELETE_COMMENT_SUCCESS:
				ResponeResult delete_result = (ResponeResult)msg.obj;
				int commentId = delete_result.getCode();
				for (int i = 0; i < list.size(); i++) {
					if (list.get(i).getId() == commentId) {
						list.remove(i);
						break;
					}
				}
				if (adapter != null) {
					adapter.notifyDataSetChanged();
				}
				break;
			case DELETE_COMMENT_FAIL:
				CommonMethod.makeNotice(CommentActivity.this, msg.obj.toString());
				break;
			}
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
//		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.comment_activity);
		initView();
		getData();
		TemporaryVariable.activities.push(this);
	}

	private void initView() {
//		main_view = (ScrollView) findViewById(R.id.main_view);
		view_edit = findViewById(R.id.view_edit);
		lvProductFooter = getLayoutInflater().inflate(R.layout.listview_footer, null);
		lvProductFooterMore = (TextView) lvProductFooter.findViewById(R.id.listview_foot_more);
		lvProductFooterProgress = (ProgressBar) lvProductFooter.findViewById(R.id.listview_foot_progress);
		lvBtn_more = (TextView) lvProductFooter.findViewById(R.id.btn_more);
		lvLinear_more = (LinearLayout) lvProductFooter.findViewById(R.id.linear_more);
		lvProductFooterMore.setVisibility(View.GONE);
		lvProductFooter.setVisibility(View.GONE);
		if (TextUtils.isEmpty(MyUserInfo.getInstance().getUserInfoBean().getSessionId())) {
			view_edit.setVisibility(View.VISIBLE);
		}else {
			view_edit.setVisibility(View.GONE);
		}
		rel_mid = (RelativeLayout) findViewById(R.id.rel_mid);
		rel_main = (RelativeLayout) findViewById(R.id.rel_main);
		rel_main.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (TextUtils.isEmpty(et_comment.getText().toString()+"")) {
					tv_comment.setTag("0");
					et_comment.setHint("发表读后感...");
				}
				InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
				imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
			}
		});
		
		view_edit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				checkUserLogin(CommentActivity.this);
			}
		});
		activity_base_title = (LinearLayout) findViewById(R.id.activity_base_title);
		et_comment = (EditText) findViewById(R.id.et_comment);
		tv_comment = (TextView) findViewById(R.id.tv_comment);
		et_comment.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				if ("".equals(et_comment.getText().toString())) {
					tv_comment.setEnabled(false);// 无内容是不可点击
				} else {
					tv_comment.setEnabled(true);// 有内容时可以点击
				}
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
				
			}

			@Override
			public void afterTextChanged(Editable s) {

			}
		});
		et_comment.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
			}
		});
		tv_comment.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (checkUserLogin(CommentActivity.this)) {
					addComment(et_comment.getText().toString(),v.getTag().toString());
				}
			}
		});
		tv_comment.setTag("0");
		image_render = (ImageView) findViewById(R.id.image_render);
		view = findViewById(R.id.text);
		text2 = findViewById(R.id.text2);
		text2.getBackground().setAlpha(200);
		applyBlur();
		Intent intent = getIntent();
		bookId = intent.getIntExtra("bookId", 0);
		bookName = intent.getStringExtra("bookName");
		imgFacePlay = intent.getStringExtra("imgFacePlay");
		ImageLoader.getInstance().displayImage(intent.getStringExtra("imgFace"), image_render);
		findViewById(R.id.activity_base_back).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		comment_listview = (PullToRefreshListView) findViewById(R.id.comment_listview);
		adapter = new CommentAdapter(this, list, handle);
		comment_listview.setAdapter(adapter);
		comment_listview.setTag(0);
		
		comment_listview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, final int position, final long id) {
				InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
				imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
				int[] location = new int[2];
				view.getLocationOnScreen(location);
				location[1] += 100;
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("isSelf", list.get(position - 1).getIsSelf());
				MyPopWindowDialog dialog = new MyPopWindowDialog(CommentActivity.this, map, location, view);
				dialog.setOnClickDelete(new IPopDialogOnclickInterface() {

					@Override
					public void OnShareClick(Map<String, Object> map) {
						String url = HttpCommonInfo.MURL +"book-comment-share?bookId=" + bookId + "&id=" + id;
						String title = list.get(position - 1).getName() + "的读后感";
						String content = bookName;
						new ShareView(CommentActivity.this, CommentActivity.this).setTitle(title).setUrl(url).setContent(content).setImageUrl(imgFacePlay).setType(4).setId(bookId+"").show(findViewById(R.id.main_view));
					}

					@Override
					public void OnRepClick(Map<String, Object> map) {
						if (CommonMethod.checkUserLogin(CommentActivity.this)) {
							tv_comment.setTag(id+"");
							et_comment.setHint("回复  "+list.get(position - 1).getName()+"...");
							et_comment.requestFocus();
							InputMethodManager imm = (InputMethodManager)et_comment.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
							imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
						}
					}

					@Override
					public void onDeleteClick(Map<String, Object> map) {
						CommentBean commentBean = list.get(position - 1);
						if (commentBean != null && commentBean.getIsSelf() == 2) {
							CommonAlertDialog alertDialog = new CommonAlertDialog(CommentActivity.this);
							alertDialog.setTextMessage("确定要删除这条评论吗？");
							alertDialog.setShowTitle(true);
							String[] a = {"确定","取消"};
							alertDialog.setBtns(new DialogListener() {

								@Override
								public void okButtonClick(Dialog dialog) {
									deleteComment(list.get(position - 1).getId(), bookId);
									dialog.dismiss();
								}

								@Override
								public void cancelButtonClick(Dialog dialog) {
									dialog.dismiss();
								}

								@Override
								public void otherButtonClick(Dialog dialog) {
									dialog.dismiss();
								}}, a);
							alertDialog.show();
						}
					}
				});
				dialog.showDialog();
			}
		});
		
		comment_listview.setOnRefreshListener(new OnRefreshListener() {
			
			@Override
			public void onRefresh() {
				pageIndex = 0;
				getData();
			}
		});
		
		comment_listview.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
				CommentBean commentBean = list.get(position - 1);
				if (commentBean != null && commentBean.getIsSelf() == 2) {
					CommonAlertDialog alertDialog = new CommonAlertDialog(CommentActivity.this);
					alertDialog.setTextMessage("确定要删除这条评论吗？");
					alertDialog.setShowTitle(true);
					String[] a = {"确定","取消"};
					alertDialog.setBtns(new DialogListener() {

						@Override
						public void okButtonClick(Dialog dialog) {
							deleteComment(list.get(position - 1).getId(), bookId);
							dialog.dismiss();
						}

						@Override
						public void cancelButtonClick(Dialog dialog) {
							dialog.dismiss();
						}

						@Override
						public void otherButtonClick(Dialog dialog) {
							dialog.dismiss();
						}}, a);
					alertDialog.show();
				}
				return true;
			}
		});
		
		comment_listview.addFooterView(lvProductFooter);
		lvBtn_more.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				getData();
			}
		});
		comment_listview.setOnScrollListener(new OnScrollListener() {
			
			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				comment_listview.onScrollStateChanged(view, scrollState);
				boolean scrollEnd = false;
				try {
					if (view.getPositionForView(lvProductFooter) == view.getLastVisiblePosition()
							&& !lvProductFooterMore.getText().toString().equals("没有更多数据了")) {
						scrollEnd = true;
					}
				} catch (Exception e) {
					scrollEnd = false;
				}
				
				int lvDataState = Integer.parseInt((comment_listview.getTag().toString()));
				if (scrollEnd && lvDataState == 0) {
					comment_listview.setTag(1);
					lvProductFooterMore.setText("加载中");
					lvProductFooterProgress.setVisibility(View.VISIBLE);
					lvLinear_more.setVisibility(View.VISIBLE);
					lvBtn_more.setVisibility(View.GONE);
					int page = comment_listview.getCount() - 2;  // 减去ListView的头和尾的
					getData();
				}
			}
			
			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				comment_listview.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
			}
		});
		
	}
	
	
	private void getData(){
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(CommentActivity.this, HttpRequestHelper.USERID, 0))));
		params.add(new BasicNameValuePair(HttpRequestHelper.BOOKID, bookId+""));
		params.add(new BasicNameValuePair(HttpRequestHelper.PAGE_INDEX, String.valueOf(pageIndex)));
		HttpRequestHelper.executeHttpData(this, HttpRequestHelper.BOOK_COMMENT_LIST, params, handle, HttpRequestHelper.GETDATA_SUCCESS);
	}
	
	
	private void addFavor(final int commendId){
		//请求数据
		Pool.getPool().execute(new Runnable() {
			@Override
			public void run() {
				List<NameValuePair> params = new ArrayList<NameValuePair>();
				params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(CommentActivity.this, HttpRequestHelper.USERID, 0))));
				params.add(new BasicNameValuePair(HttpRequestHelper.BOOKID, bookId+""));
				params.add(new BasicNameValuePair(HttpRequestHelper.COMMENTID, String.valueOf(commendId)));
				ResponeResult responeResult = new ResponeResult();
				try {
					HttpEntity entity = HttpHelper.getInfoByPost(HttpRequestHelper.BOOK_COMMENT_FAVOR, params, CommentActivity.this);
					String _result = HttpHelper.entity2String(entity);
					JSONObject jsonResult = new JSONObject(_result);
					JSONObject result = jsonResult.getJSONObject(HttpCommonInfo.RESULT);
					int code = result.getInt(HttpCommonInfo.RESULT_CODE);
					String msg = result.getString(HttpCommonInfo.RESULT_MSG);
					responeResult.setCode(code);
					responeResult.setMsg(msg);
					if (code == 0) {
						responeResult.setCode(commendId);
						handle.obtainMessage(CLICK_FAVOR_SUCCESS, responeResult).sendToTarget();
					} else {
						handle.obtainMessage(CLICK_FAVOR_FAILE, responeResult).sendToTarget();
					}
				} catch (ClientProtocolException e) {
					e.printStackTrace();
					responeResult = null;
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
					responeResult = null;
				} catch (IOException e) {
					e.printStackTrace();
					responeResult = null;
				} catch (JSONException e) {
					e.printStackTrace();
					responeResult = null;
				}
			}
		});
	}
	
	/**
	 * 删除评论
	 * @param commendId
	 * @param bookId
	 */
	private void deleteComment(final int commendId, final int bookId){
		//请求数据
		Pool.getPool().execute(new Runnable() {
			@Override
			public void run() {
				List<NameValuePair> params = new ArrayList<NameValuePair>();
				params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(CommentActivity.this, HttpRequestHelper.USERID, 0))));
				params.add(new BasicNameValuePair(HttpRequestHelper.BOOKID, bookId+""));
				params.add(new BasicNameValuePair(HttpRequestHelper.COMMENTID, String.valueOf(commendId)));
				ResponeResult responeResult = new ResponeResult();
				try {
					HttpEntity entity = HttpHelper.getInfoByPost(HttpRequestHelper.BOOK_COMMENT_DELETE, params, CommentActivity.this);
					String _result = HttpHelper.entity2String(entity);
					JSONObject jsonResult = new JSONObject(_result);
					JSONObject result = jsonResult.getJSONObject(HttpCommonInfo.RESULT);
					int code = result.getInt(HttpCommonInfo.RESULT_CODE);
					String msg = result.getString(HttpCommonInfo.RESULT_MSG);
					responeResult.setCode(code);
					responeResult.setMsg(msg);
					if (code == 0) {
						responeResult.setCode(commendId);
						handle.obtainMessage(DELETE_COMMENT_SUCCESS, responeResult).sendToTarget();
					} else {
						handle.obtainMessage(DELETE_COMMENT_FAIL, responeResult).sendToTarget();
					}
				} catch (ClientProtocolException e) {
					e.printStackTrace();
					responeResult = null;
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
					responeResult = null;
				} catch (IOException e) {
					e.printStackTrace();
					responeResult = null;
				} catch (JSONException e) {
					e.printStackTrace();
					responeResult = null;
				} finally {
					if (responeResult == null ) {
						handle.obtainMessage(DELETE_COMMENT_FAIL, getResources().getString(R.string.connect_err_io)).sendToTarget();
					}
				}
			}
		});
	}
	
	
	
	
	/**
	 * 发送评论
	 * @param comment
	 */
	private void addComment(final String comment,final String replyId){
		//请求数据
		Pool.getPool().execute(new Runnable() {
			@Override
			public void run() {
				List<NameValuePair> params = new ArrayList<NameValuePair>();
				params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(CommentActivity.this, HttpRequestHelper.USERID, 0))));
				params.add(new BasicNameValuePair(HttpRequestHelper.BOOKID, bookId+""));
				params.add(new BasicNameValuePair(HttpRequestHelper.COMMENT, comment));
				params.add(new BasicNameValuePair("replyId", replyId));
				ResponeResult responeResult = new ResponeResult();
				try {
					HttpEntity entity = HttpHelper.getInfoByPost(HttpRequestHelper.BOOK_COMMENT_ADD, params, CommentActivity.this);
					String _result = HttpHelper.entity2String(entity);
					JSONObject jsonResult = new JSONObject(_result);
					JSONObject result = jsonResult.getJSONObject(HttpCommonInfo.RESULT);
					int code = result.getInt(HttpCommonInfo.RESULT_CODE);
					String msg = result.getString(HttpCommonInfo.RESULT_MSG);
					responeResult.setCode(code);
					responeResult.setMsg(msg);
					if (code == 0) {
						responeResult.setData(jsonResult.getString(HttpCommonInfo.DATA));
						handle.obtainMessage(ADD_FAVOR_SUCCESS, responeResult).sendToTarget();
					} else {
						handle.obtainMessage(CLICK_FAVOR_FAILE, responeResult).sendToTarget();
					}
				} catch (ClientProtocolException e) {
					e.printStackTrace();
					responeResult = null;
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
					responeResult = null;
				} catch (IOException e) {
					e.printStackTrace();
					responeResult = null;
				} catch (JSONException e) {
					e.printStackTrace();
					responeResult = null;
				}finally{
					if (responeResult == null) {
						responeResult = new ResponeResult();
						responeResult.setMsg(getResources().getString(R.string.connect_err_io));
						handle.obtainMessage(CLICK_FAVOR_FAILE, responeResult).sendToTarget();
					}
				}
			}
		});
	}
	
	private int time = HttpRequestHelper.BLUR_DEFAULT_TIMES;
	/***
	 * 处理高斯模糊
	 */
	public void applyBlur() {
		image_render.getViewTreeObserver().addOnPreDrawListener(
				new ViewTreeObserver.OnPreDrawListener() {
					@Override
					public boolean onPreDraw() {
						if (time > 0) {
							time --;
						}else {
							image_render.getViewTreeObserver().removeOnPreDrawListener(this);
						}
						image_render.buildDrawingCache();
						Bitmap bmp = image_render.getDrawingCache();
						FastBlur.blur(bmp, view, CommentActivity.this);
						return true;
					}
		});
	}
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, final Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 100 && resultCode == 203 && data != null) {
			Pool.getPool().execute(new Runnable() {
				@Override
				public void run() {
					HttpRequestHelper.login2(CommentActivity.this,data.getStringExtra("userId"), data.getStringExtra("nickName"),
							data.getStringExtra("headImgUrl"), data.getBooleanExtra("isweixin",false), handle);
				}
			});
		}else if (requestCode == 100 && resultCode == 204) {
			view_edit.setVisibility(View.GONE);
			EventBus.getEventBus("login_refreshUI").post(new LoginSuccessEvent());
		}
	}
	
	public boolean checkUserLogin(final Activity context){
		boolean flag = true;
		if (TextUtils.isEmpty(MyUserInfo.getInstance().getUserInfoBean().getSessionId())) {
			flag = false;
			CommonAlertDialog alertDialog = new CommonAlertDialog(context);
			alertDialog.setTextMessage(context.getResources().getString(R.string.text_no_login_comment));
			alertDialog.setShowTitle(true);
			String[] a = {context.getResources().getString(R.string.text_goto_login),context.getResources().getString(R.string.app_cancel)};
			alertDialog.setBtns(new DialogListener() {
				
				@Override
				public void otherButtonClick(Dialog dialog) {
					dialog.dismiss();
				}
				
				@Override
				public void okButtonClick(Dialog dialog) {
					dialog.dismiss();
					Intent intent = new Intent(context, LoginActivity.class);
					context.startActivityForResult(intent, 100);
				}
				
				@Override
				public void cancelButtonClick(Dialog dialog) {
					dialog.dismiss();
				}
			},a);
			alertDialog.show();
		}
		return flag;
	}

	@Override
	public boolean handleMessage(Message msg) {
		ShareOpUtils.handleShareCallBack(this, msg);
		return false;
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		TemporaryVariable.activities.removeElement(this);
		super.onDestroy();
	}
	
}
